/*
channel
select: 单个流程下一个go只能监控一个channel的状态，select可以完成监控多个channel的状态。
https://www.bilibili.com/video/BV1gf4y1r79E/?p=32&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
*/
package main

import "fmt"

func fibonacii(c chan int, quit chan int) {
	x, y := 1, 1

	for {
		select {
		case c <- x:
			// 如果c可写，则该case就会进来
			x = y
			y = x + y
		case <-quit:
			fmt.Println("quit")
			return
		}
	}
}

func main() {
	fmt.Println("channel select")

	c := make(chan int)
	quit := make(chan int)

	go func() {
		for i := 0; i < 6; i++ {
			fmt.Println(<-c)
		}
		quit <- 0
	}()

	fibonacii(c, quit)
}
